package com.cskaoyan.controller.usercontroller;

import com.cskaoyan.bean.bo.AdminUserUpdateBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.po.MarketUser;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

/**
 * @author wei
 * @since 2022/09/06 20:43
 */
@RestController
@RequestMapping("admin")
public class UserController {
    @Autowired
    UserService userService;

    //请求网址: http://localhost:8083/admin/user/list?
    // page=1&limit=20&sort=add_time&order=desc
//请求方法: GET
//状态代码: 200
//    查找会员
    @GetMapping("user/list")
    @RequiresPermissions("GET /admin/user/list")
    @Cacheable(value = "admin::user", keyGenerator = "customKeyGenerator")
    public BaseRespVo queryUserList(int page, int limit, String username, String mobile, String sort, String order) {
        AdminUserListVO adminUserListVO = userService.queryUserList(page, limit, username, mobile, sort, order);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(adminUserListVO);
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }


    //请求网址: http://localhost:8083/admin/user/detail?id=1
//请求方法: GET
//状态代码: 200
//    输入id查找会员
    @GetMapping("user/detail")
    @Cacheable(value = "admin::user", keyGenerator = "customKeyGenerator")
    public BaseRespVo queryUserById(int id) {
        MarketUser marketUser = userService.queryUserById(id);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        baseRespVo.setData(marketUser);
        return baseRespVo;
    }

    //    请求网址: http://182.92.235.201:8083/admin/user/update
//请求方法: POST
//状态代码: 200
//    修改用户信息
    @PostMapping("user/update")
    @CacheEvict(value = "admin::user",allEntries = true)
    public BaseRespVo userUpdate(@RequestBody AdminUserUpdateBO adminUserUpdateBO) {
        userService.userUpdate(adminUserUpdateBO);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(1);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }

    //    请求网址: http://182.92.235.201:8083/admin/address/list?page=1&limit=20&sort=add_time&order=desc
//请求方法: GET
//状态代码: 200
//    显示收获地址
    @GetMapping("address/list")
    public BaseRespVo addressList(int page, int limit, String sort, String order, String name, Integer userId) {
        AdminAddressListVO adminAddressListVO = userService.queryAddressList(page, limit, sort, order, name, userId);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(adminAddressListVO);
        return baseRespVo;
    }

    //    请求网址: http://182.92.235.201:8083/admin/footprint/list?
//    page=1&limit=20&userId=1&goodsId=1&sort=add_time&order=desc
//请求方法: GET
//状态代码: 200
//    会员足迹
    @GetMapping("footprint/list")
    public BaseRespVo footprintList(int page, int limit, Integer userId, Integer goodsId, String sort, String order) {
        AdminFootPrintListVO adminFootPrintListVO = userService.queryFootprintList(page, limit, userId, goodsId, sort, order);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(adminFootPrintListVO);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }

    //    请求网址: http://182.92.235.201:8083/admin/history/list?
//    page=1&limit=20&userId=&keyword=&sort=add_time&order=desc
//请求方法: GET
//状态代码: 200
//    搜索历史
    @GetMapping("history/list")
    public BaseRespVo historyList(int page, int limit, Integer userId, String keyword, String sort, String order) {
        AdminHistoryListVO adminHistoryListVO = userService.queryHistoryList(page, limit, keyword, userId, sort, order);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(adminHistoryListVO);
        return baseRespVo;
    }

    //   请求网址: http://182.92.235.201:8083/admin/collect/list?
//   page=1&limit=20&userId=1&valueId=1&sort=add_time&order=desc
//请求方法: GET
//状态代码: 200
    @GetMapping("collect/list")
    public BaseRespVo collectList(int page, int limit, Integer userId, Integer valueId, String sort, String order) {
        AdminCollectListVo adminCollectListVo = userService.queryCollectList(page, limit, userId, valueId, sort, order);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(adminCollectListVo);
        return baseRespVo;
    }


    //    请求网址: http://182.92.235.201:8083/admin/feedback/list?
//    page=1&limit=20&username=A&sort=add_time&order=desc&id=A
//请求方法: GET
//状态代码: 200
//    意见反馈
    @GetMapping("feedback/list")
    public BaseRespVo feedBack(int page, int limit, String username, Integer id, String sort, String order) {
        AdminFeedBackListVO adminFeedBackListVO = userService.queryfeedBackList(page, limit, username, id, sort, order);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(adminFeedBackListVO);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }
}

